package cn.geminis.job.worker.processor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.stereotype.Component;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;

@Slf4j
@Component
public class SpelHttpProcessor extends tech.powerjob.official.processors.impl.HttpProcessor {

    private static final SpelExpressionParser PARSER = new SpelExpressionParser();

    @Override
    public ProcessResult process(TaskContext taskContext) throws Exception {

        var parsedJobParams = PARSER.parseExpression(taskContext.getJobParams()).getValue(String.class);
        if (log.isDebugEnabled()) {
            log.debug("Parsed JobParams:{}", parsedJobParams);
        }

        taskContext.setJobParams(parsedJobParams);

        return super.process0(taskContext);
    }
}
